<template>
  <a-card :bordered="false">
    <a-row :gutter="24">
      <a-form :form="form" @submit="handleSubmit">
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="工作名称">
            <a-input
              :disabled="isO"
              placeholder="请输入工作名称"
              v-decorator="[
          'workName',
          {
            rules: [
              {
                required: true,
                message: '工作名称不能为空',
              },
            ],
          },
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="批次号">
            <a-input
              :disabled="true"
              placeholder="请输入批次号"
              v-decorator="[
          'peiCiHao',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="24">
          <a-form-item v-bind="formItemLayout2" label="内容描述">
            <a-textarea
              :disabled="isO"
              placeholder="请输入内容描述"
              :rows="4"
              v-decorator="[
          'neiRongMiaoShu',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="年度(起始)">
            <j-dict-select-tag
              :disabled="isO"
              type="list"
              v-decorator="[
                  'nianDuQiShi',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请选择年度(起始)'
                      }
                    ]
                  }
                ]"
              :trigger-change="true"
              dictCode="NianDu"
              placeholder="请选择年度(起始)"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="年度(终止)">
            <j-dict-select-tag
              :disabled="isO"
              type="list"
              v-decorator="[
                  'nianDuZhongZhi',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请选择年度(终止)'
                      }
                    ]
                  }
                ]"
              :trigger-change="true"
              dictCode="NianDu"
              placeholder="请选择年度(终止)"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="载体号(起始)">
            <a-input-number
              :disabled="isO"
              style="width: 100%"
              :min="0"
              placeholder="请输入载体号(起始)"
              v-decorator="['zaiTiHaoQiShi',{
            rules: [
              {
                required: true,
                message: '载体号(起始)不能为空',
              },
            ],
          }]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="载体号(终止)">
            <a-input-number
              :disabled="isO"
              style="width: 100%"
              :min="0"
              placeholder="请输入载体号(终止)"
              v-decorator="['zaiTiHaoZhongZhi',{
            rules: [
              {
                required: true,
                message: '载体号(终止)不能为空',
              },
            ],
          }]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="载体类型">
            <j-dict-select-tag
              :disabled="isO"
              type="list"
              v-decorator="[
              'zaiTiLeiXing',
              {
            rules: [
              {
                required: true,
                message: '请选择载体类型',
              },
            ],
          },
              ]"
              :trigger-change="true"
              dictCode="ZaiTiLeiXing"
              placeholder="请选择载体类型"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="载体数量">
            <a-input-number
              :disabled="isO"
              style="width: 100%"
              :min="0"
              placeholder="请输入载体数量"
              v-decorator="[
          'zaiTiShuLiang',
          {
            rules: [
              {
                required: true,
                message: '载体数量不能为空',
              },
            ],
          },
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="电子档案数量">
            <a-input-number
              :disabled="isO"
              style="width: 100%"
              :min="0"
              placeholder="请输入电子档案数量"
              v-decorator="['dangAnShuLiang',{
            rules: [
              {
                required: true,
                message: '电子档案数量不能为空',
              },
            ],
          }]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="数据大小(MB)">
            <a-input-number
              :disabled="isO"
              style="width: 100%"
              :min="0"
              placeholder="请输入数据大小"
              v-decorator="['shuJuDaXiao',{
            rules: [
              {
                required: true,
                message: '数据大小不能为空',
              },
            ],
          }]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="四性检查-真实性">
            <a-input
              :disabled="true"
              placeholder="请输入四性检查-真实性"
              v-decorator="[
          'siXingZhenShiBiaoShi',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="四性检查-完整性">
            <a-input
              :disabled="true"
              placeholder="请输入四性检查-完整性"
              v-decorator="[
          'siXingWanZhengBiaoShi',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="四性检查-可用性">
            <a-input
              :disabled="true"
              placeholder="请输入四性检查-可用性"
              v-decorator="[
          'siXingKeYongBiaoShi',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="四性检查-安全性">
            <a-input
              :disabled="true"
              placeholder="请输入四性检查-安全性"
              v-decorator="[
          'siXingAnQuanBiaoShi',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="移交者">
            <a-input
              :disabled="isF"
              placeholder="请输入移交者"
              v-decorator="[
          'yiJiaoZhe',
          {
            rules: [
              {
                required: true,
                message: '移交者不能为空',
              },
            ],
          }
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="移交接收方式">
            <j-dict-select-tag
              :disabled="isO"
              type="list"
              v-decorator="['yiJiaoJieShouFangShi', {
            rules: [
              {
                required: true,
                message: '请选择移交接收方式',
              },
            ],
          },]"
              :trigger-change="true"
              dictCode="YiJiaoJieShouFangShi"
              placeholder="请选择移交接收方式"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="移交单位">
            <j-select-depart
              :disabled="isO"
              v-decorator="['yiJiaoDanWei',{
            rules: [
              {
                required: true,
                message: '请选择移交单位',
              },
            ],
          }]"
              :trigger-change="true"
            ></j-select-depart>
          </a-form-item>
        </a-col>

        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="移交日期">
            <j-date
              :disabled="isO"
              placeholder="请选择移交日期"
              v-decorator="['yiJiaoRiQi',{
            rules: [
              {
                required: true,
                message: '请选择移交日期',
              },
            ],
          }]"
              :trigger-change="true"
              style="width: 100%"
            />
            <!-- <a-date-picker
              show-time
              format="YYYY-MM-DD HH:mm:ss"
              style="width:100%"
              @change="onChangeYJ"
              v-decorator="[
              'createTimeYJ',
              ]"
            />-->
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="审核者">
            <a-input
              :disabled="isO"
              placeholder="请输入审核者"
              v-decorator="[
          'shenHeZhe',
        ]"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="审核日期">
            <j-date
              :disabled="isO"
              placeholder="请选择审核日期"
              v-decorator="['shenHeRiQi']"
              :trigger-change="true"
              style="width: 100%"
            />
            <!-- <a-date-picker
              show-time
              format="YYYY-MM-DD HH:mm:ss"
              style="width:100%"
              @change="onChangeSH"
              v-decorator="[
              'shenHeRiQi',
              ]"
            />-->
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="审核状态">
            <j-dict-select-tag
              :disabled="isO"
              type="list"
              v-decorator="['shengHeBiaoShi']"
              :trigger-change="true"
              dictCode="ShenHeZhuangTai"
              placeholder="请选择审核状态"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12">
          <a-form-item v-bind="formItemLayout" label="归档方式">
            <j-dict-select-tag
              :disabled="true"
              type="list"
              v-decorator="['guiDangFangShi']"
              :trigger-change="true"
              dictCode="GuiDangFangShi"
              placeholder="请选择审核状态"
            />
          </a-form-item>
        </a-col>
        <a-col :md="24">
          <div class="antBtn">
            <a-button type="primary" html-type="submit" v-if="yjF">保存</a-button>
            <a-button type="primary" style="margin-left:8px" @click="qingCe" v-if="isF">移交清册</a-button>
            <a-button type="primary" style="margin-left:8px" @click="zhuiJia" v-if="isF&&yjF">追加</a-button>
            <a-button type="primary" style="margin-left:8px" @click="fanHui">返回</a-button>
          </div>
        </a-col>
      </a-form>
    </a-row>
  </a-card>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
import moment from 'moment'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JDate from '@/components/jeecg/JDate'
import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
export default {
  name: 'YiJiaoDengJi',
  components: {
    JDate,
    JDictSelectTag,
    JSelectDepart,
  },
  data() {
    return {
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
      },
      formItemLayout2: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
      },
      kuData: [],
      form: this.$form.createForm(this, { name: 'register' }),
      isF: false,
      yjF: true,
      isO: false,
    }
  },
  created() {
    if (this.$route.query.id) {
      this.edit()
      this.isF = true
    }
    if (this.$route.query.ids) {
      const {
        form: { setFieldsValue },
      } = this
      this.$nextTick(() => {
        setFieldsValue({
          guiDangFangShi: this.$route.query.keys,
        })
      })
    }
  },
  methods: {
    // 详情
    edit() {
      getAction(`/yjYiJiaoJieShou/queryById?id=${this.$route.query.id}`, {}).then((res) => {
        const data = res.result
        if (data.zhuangTai == 3) {
          this.yjF = false
          this.isO = true
        }
        const {
          form: { setFieldsValue },
        } = this
        this.$nextTick(() => {
          setFieldsValue({
            workName: data.workName,
            peiCiHao: data.peiCiHao,
            nianDuQiShi: data.nianDuQiShi,
            nianDuZhongZhi: data.nianDuZhongZhi,
            zaiTiHaoQiShi: data.zaiTiHaoQiShi,
            zaiTiHaoZhongZhi: data.zaiTiHaoZhongZhi,
            dangAnShuLiang: data.dangAnShuLiang,
            shuJuDaXiao: data.shuJuDaXiao,
            zaiTiLeiXing: data.zaiTiLeiXing,
            zaiTiShuLiang: data.zaiTiShuLiang,
            yiJiaoJieShouFangShi: data.yiJiaoJieShouFangShi,
            siXingZhenShiBiaoShi: data.siXingZhenShiBiaoShi,
            siXingWanZhengBiaoShi: data.siXingWanZhengBiaoShi,
            siXingKeYongBiaoShi: data.siXingKeYongBiaoShi,
            siXingAnQuanBiaoShi: data.siXingAnQuanBiaoShi,
            yiJiaoZhe: data.yiJiaoZhe,
            yiJiaoDanWei: data.yiJiaoDanWei,
            yiJiaoRiQi: data.yiJiaoRiQi,
            shenHeZhe: data.shenHeZhe,
            shenHeRiQi: data.shenHeRiQi,
            shengHeBiaoShi: data.shengHeBiaoShi,
            guiDangFangShi: data.guiDangFangShi,
          })
        })
      })
    },
    // 提交
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          values.beiYong1 = this.$route.query.keys
          values.beiYong2 = this.$route.query.ids
          let body = values
          if (this.isF) {
            body.id = this.$route.query.id
            postAction('/yjYiJiaoJieShou/edit', { ...body }).then((res) => {
              if (res.code == 200) {
                this.$message.success(res.message)
              } else {
                this.$message.error(res.message)
              }
            })
          } else {
            postAction('/yjYiJiaoJieShou/add', { ...body }).then((res) => {
              if (res.code == 200) {
                this.$message.success(res.message)
                this.$router.push({ path: '/yijiao-tiqu' })
              } else {
                this.$message.error(res.message)
              }
            })
          }
        }
      })
    },
    // 返回
    fanHui() {
      if (this.$route.query.id) {
        this.$router.push({ path: '/yijiao-list' })
      } else {
        this.$router.push({ path: '/yijiao-tiqu' })
      }
    },
    // 清册
    qingCe() {
      this.$router.push({ path: '/yijiao-qingce', query: { id: this.$route.query.id, keys: this.$route.query.keys } })
    },
    // 追加
    zhuiJia() {
      this.$router.push({ path: '/yijiao-zuijia', query: { id: this.$route.query.id, keys: this.$route.query.keys } })
    },
  },
}
</script>

<style lang="less">
.antBtn {
  text-align: right;
}
</style>